import express from 'express';
import tbApi from '../../lib/tbapi'; // 淘宝接口API
import CONFIG from '../../../config/config.config'; // CONFIG
// import { checkPermission } from '../../utils/utils'; // 工具类

const router = express.Router();

router.post('/', async function (Request, Response, next) {
  let param = Request.body
  tbApi.index({
    method: 'taobao.wireless.share.tpwd.query', // 查询淘礼金信息
    password_content: param.tkl, // 官方的物料Id
  }).then(res => {
    if (res.error_response) {
      // 接口返回出错信息
      Response.status(300).send({ message: '口令转换失败，请检查您复制的口令是否正确' });
    } else {
      let urls1 = res.wireless_share_tpwd_query_response.url.split('i')
      let urls2 = urls1[1].split('.')[0]
      let url = encodeURI(`https://item.taobao.com/item.htm?id=${urls2}`)
      Response.json({
        data: url
      });
    }
  })
});

module.exports = router;